/*
	Code for handling clickable events.
	Requires jQuery library for AJAX input.

*/



// Change span to input
function ajax_clickable_spaninput_onmouseup( span_id, hidden_id ) {
	s = document.getElementById( span_id );

	// Replace double-quotes with 2 single quotes.
	s.innerHTML = s.innerHTML.replace(/"/g, "''" );

	s.innerHTML = "<input type='text' id='clickable_" + span_id +
		"' value=\"" + s.innerHTML +
		"\" /><button type='button' onclick='" +
		"javascript:ajax_clickable_spaninput_onsubmit(\"" + span_id +
		"\", \"" + hidden_id + "\");'>Set</button>";
	s.onmouseup = null;
}
// Change input back to span and save results in hidden_id
function ajax_clickable_spaninput_onsubmit( span_id, hidden_id ) {
	// Transfer data from input to span & hidden control.
	v = document.getElementById( "clickable_" + span_id );
	s = document.getElementById( span_id );
	h = document.getElementById( hidden_id );
	s.innerHTML = v.value;
	h.value = v.value;

	// Turn on the span clickable property again.
	s.onmouseup = function() {ajax_clickable_spaninput_onmouseup(span_id, hidden_id);};

	// Make sure span  doesn't have styling still applied.
	s.style.background='';
}
